package com.example.tellwin.home.presenter;

import com.example.tellwin.api.TwjfApi;
import com.example.tellwin.base.RxPresenter;
import com.example.tellwin.base.SimpleCallback;
import com.example.tellwin.home.bean.ContentBean;
import com.example.tellwin.home.contract.QuestionDetailContract;
import com.example.tellwin.utils.HttpUtils;

import javax.inject.Inject;

import okhttp3.RequestBody;

/**
 * @author : LinZePeng
 * @date : 2020/11/26
 * @Describe ：
 **/
public class QuestionDetailPresenter extends RxPresenter<QuestionDetailContract.View> implements QuestionDetailContract.Presenter<QuestionDetailContract.View> {


    private TwjfApi mApi;

    @Inject
    public QuestionDetailPresenter(TwjfApi mApi) {
        this.mApi = mApi;
    }


    @Override
    public void getQuestionDetail(String questionId) {
        mApi.getQuestionDetail(questionId , new SimpleCallback<ContentBean>(mView) {
            @Override
            public void onSuccess(ContentBean contentBean) {
                mView.questionDetailResult(contentBean.getQuestion());
            }

            @Override
            public void onFail(String msg) {

            }
        });
    }

    @Override
    public void attention(String questionId) {
        RequestBody requestBody = HttpUtils.getRequestBody("followType", "1" + "", "relationId", questionId, "relationType", "0");
        mApi.follow(requestBody, new SimpleCallback<Object>(mView) {
            @Override
            public void onSuccess(Object o) {
                mView.attention();
            }

            @Override
            public void onFail(String msg) {

            }
        });
    }
}
